<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%--
  Created by IntelliJ IDEA.
  User: Wangliwei
  Date: 2017/6/18
  Time: 21:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<%if(session.getAttribute("uname")!=null)
{// 用户已登陆%>
<%!String DBDRIVER			= "com.mysql.jdbc.Driver" ;
    String DBURL			= "jdbc:mysql://127.0.0.1:3306/student" ;
    String DBUSER			= "root" ;
    String DBPASSWORD		= "" ;
    Connection conn			= null ;
    PreparedStatement pstmt	= null ;
    ResultSet rs			= null ; int id ; %>
<%try
    {id = Integer.parseInt(request.getParameter("num")) ; }
    catch(Exception e) {}%>
<%String sql = " SELECT num,name,sex,score,indate FROM students WHERE num = ?  " ; try{
    Class.forName(DBDRIVER) ;
    conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
    pstmt = conn.prepareStatement(sql) ;
   pstmt.setInt(1,id);
    rs = pstmt.executeQuery() ; %>
<%if(rs.next())
{// 进行循环打印，打印出所有的内容，以表格形式// 从数据库中取出内容
    String num = rs.getString(1) ;
    String name = rs.getString(2) ;
    String sex = rs.getString(3) ;
    String score = rs.getString(4) ;
    String indate = rs.getString(5) ;
%><form action="" method="post"><table><tr>
    <td colspan="2">查询信息显示</td></tr>
    <tr><td>学号：</td><td><input type="text" name="num" value="<%=num%>"></td></tr>
    <tr><td>姓名：</td><td><input type="text" name="name" value="<%=name%>"></td></tr>
    <tr><td>性别：</td><td><input type="text" name="sex" value="<%=sex%>"></td></tr>
    <tr><td>成绩：</td>
        <td><input type="text" name="score" value="<%=score%>"></td></tr>
    <tr><td>入学日期：</td><td><input type="text" name="indate" value="<%=indate%>"></td></tr>
</table></form>
<%}else{%>没有发现，要查找的内容！！<br>
请确认要查找的信息是否存在！！<br>
<%}%>
<%rs.close() ; pstmt.close() ; conn.close() ; }
catch(Exception e) {}%>
<h3> <a href="result.jsp">重新输入</a><br><br>
    <a href="main.jsp">回到功能列表页</a></h3>
<%}else{// 用户未登陆，提示用户登陆，并跳转
    response.setHeader("refresh","2;URL=Login.jsp") ; %>
您还未登陆，请先登陆！！！<br>
两秒后自动跳转到登陆窗口！！！<br>
如果没有跳转，请按<a href="Login.jsp">这里</a>！！！<br>
<%}%>



</body>
</html>
